package com.chunxiadong.handler;

import org.apache.log4j.Logger;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;

/**
 * @auther QiuShangcheng
 * @create 2021/6/5
 */
/*处理服务器内部发生问题时的跳转与异常报告*/
@ControllerAdvice
public class ControllerExceptionHandler extends  RuntimeException{
    private final Logger log = Logger.getLogger(this.getClass());

    @ExceptionHandler(Exception.class)
    public ModelAndView exceptionHandler(HttpServletRequest request, Exception e) {
        log.error("异常报告：Request URL : {"+request.getRequestURL()+"}，Exception : {"+e+"}");
        ModelAndView mv = new ModelAndView();
        mv.addObject("url",request.getRequestURI());
        mv.addObject("exception",e);
        mv.setViewName("error/error");
        return mv;
    }

}
